import java.util.*;
class Spreadsheet {
    private final Map<Integer, int[]> cells = new HashMap<>();
    public Spreadsheet(int rows) {
        for(int i = 0; i< 26; i++){
            cells.put(i, new int[rows]);
        }
    }
    
    public void setCell(String cell, int value) {
        int col = cell.charAt(0) - 'A';
        int row = Integer.parseInt(cell.substring(1));
        cells.get(col)[row - 1] = value;
    }
    
    public void resetCell(String cell) {
        int col = cell.charAt(0) - 'A';
        int row = Integer.parseInt(cell.substring(1));
        cells.get(col)[row - 1] = 0;
    }
    
    public int getValue(String formula) {
        int plusIndex = formula.indexOf('+');
        int valueX = getCell(formula.substring(0, plusIndex));
        int valueY = getCell(formula.substring(plusIndex + 1));
        return valueX + valueY;
    }
    private int getCell(String cell){
        if (cell == null || cell.isEmpty()) {
            return 0;
        }
        try {
            // 整数判断
            return Integer.parseInt(cell);
        } catch (NumberFormatException e1) {
        
        }
        int col = cell.charAt(0) - 'A';
        int row = Integer.parseInt(cell.substring(1));
        int[] values = cells.get(col);
        if(row <= values.length){
            return values[row - 1];
        }
        return 0;
    }
}